package com.pengke.pangu.common.utils;

import com.pengke.pangu.common.enums.ResultCode;
import lombok.Data;

@Data
public final class R {

    private Integer code;

    private String msg;

    private Object data;

    private Long timestamp;

    private R(){}

    /**
     * 操作成功
     * @return Result
     */
    public static R ok() {
        R r = new R();
        r.setCode(ResultCode.OK.getCode());
        r.setMsg(ResultCode.OK.getMsg());
        r.setTimestamp(System.currentTimeMillis());
        return r;
    }

    /**
     * 操作成功带返回值
     * @param data
     * @return r
     * @param 
     */
    public static R ok(Object data) {
        R r = R.ok();
        r.setData(data);
        return r;
    }

    /**
     * 自定义返回信息
     * @param resultCode
     * @return r
     */
    public static R fail(ResultCode resultCode) {
        R r = new R();
        r.setCode(resultCode.getCode());
        r.setMsg(resultCode.getMsg());
        r.setTimestamp(System.currentTimeMillis());
        return r;
    }

    /**
     * 自定义返回信息
     * @param resultCode
     * @param msg
     * @return r
     */
    public static R fail(ResultCode resultCode,String msg) {
        R r = new R();
        r.setCode(resultCode.getCode());
        r.setMsg(msg);
        r.setTimestamp(System.currentTimeMillis());
        return r;
    }

    /**
     * 自定义返回信息
     * @param resultCode
     * @param data
     * @return r
     */
    public static R fail(ResultCode resultCode, Object data) {
        R r = R.fail(resultCode);
        r.setData(data);
        return r;
    }


}
